import React, { Component } from 'react';

const apiGetAllFlatListData = 'http://192.168.191.1:3000/people?_limit=5&_sort=id&_order=esc';


/* // 注意这个方法前面有async关键字
export const  getMoviesFromApi= async ()=> {
    try {
      // 注意这里的await语句，其所在的函数必须有async关键字声明
      let response = await fetch(
        "https://facebook.github.io/react-native/movies.json"
      );
      let responseJson = await response.json();
      console.log(responseJson);
      return responseJson.movies;
    } catch (error) {
      console.error(error);
    }
  }
 */



export const getPageFlatListData = async params => {
  try {
    //
    let response = await fetch(apiGetAllFlatListData + '&_page=' + params.page);
    let responseJson = await response.json();
    return responseJson;
  } catch (error) {
    console.log(error);
  }
};

const IdFlatListData = 'http://192.168.191.1:3000/people/';
export const getIdFlatListData = async params => {
  try {
    //
    let response = await fetch(IdFlatListData + params.id);
    let responseJson = await response.json();
    return responseJson;
  } catch (error) {
    console.log(error);
  }
};
